package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class AdresseBog here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class AdresseBog
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> person;
    private static AdresseBog instance;
    
    private AdresseBog()
    {
        person = new ArrayList<Person>();
    }
    
    public static AdresseBog getInstance()
    {
        if(instance == null)
        {
            instance = new AdresseBog();
        }
        return instance;
    }
    
    public void addPerson(Person onePerson)
    {
        person.add(onePerson);
    }
    
    public String getPerson(long id, int number)
    {        
        for(Person p : person)
        {
            if(id == p.getID())
            {
                if(number == 1)
                {
                    return p.getName();
                }
                else if(number == 2)
                {
                    return p.getAddress();
                }
                else if(number == 3)
                {
                    return p.getPostalCode();
                }
                else if(number == 4)
                {
                    return p.getCity();
                }
                else if(number == 5)
                {
                    return p.getPhone();
                }
            }
        }
        return null;
    }
    
    public void deletePerson(long id)
    {
        for(int i = 0; i < person.size(); i++)
        {
            if(id == person.get(i).getID())
            {
                person.remove(i);
            }
        }
    }
    
    public void updatePerson(long id, int number, String arg)
    {        
        for(Person p : person)
        {
            if(id == p.getID())
            {
                if(number == 1)
                {
                    p.setName(arg);
                }
                else if(number == 2)
                {
                    p.setAddress(arg);
                }
                else if(number == 3)
                {
                    p.setPostalCode(arg);
                }
                else if(number == 4)
                {
                    p.setCity(arg);
                }
                else if(number == 5)
                {
                    p.setPhone(arg);
                }
            }
        }
    }
    
    public long getID(long id)
    {
        for(Person p : person)
        {
            if(id == p.getID())
            {
                return p.getID();
            }
        }
        return 0;
    }
}
